<template>
  <!-- 导入表 -->
  <el-dialog v-myFullscreen title="物资选择" :visible.sync="visible" width="800px" top="5vh" append-to-body>
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="物资名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入物资名称" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="物资编码" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入物资编码" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <template>
      <div>
        <el-radio-group v-model="queryParams.type" @change="getList">
          <el-radio-button v-for="productConfig in productConfigOptions" :key="productConfig.id" :label="productConfig.id">{{productConfig.typeName}}</el-radio-button>
        </el-radio-group>
      </div>
    </template>
    <el-row>
      <el-table ref="table" :data="productInfoList" @selection-change="handleSelectionChange" height="260px" highlight-current-row cell-class-name="li_table">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="物资名称" align="center" prop="basicProductInfo.name" />
        <el-table-column label="物资编码" align="center" prop="basicProductInfo.code" />
        <el-table-column label="物资类别" align="center" prop="basicProductInfo.typeCodeName" />
        <!--        <el-table-column label="物资类型" align="center" prop="basicProductInfo.typeName" />-->
        <el-table-column label="规格型号" align="center" prop="basicProductInfo.model" />
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" :disabled="clickDisabled" @click="submit">确 定</el-button>
      <el-button @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  listProduct,
  listProductInfo,
} from "@/api/equipment/materials/stockIn";
// import { listProductInfo} from "@/api/basic/productInfo/productInfo";
export default {
  data() {
    return {
      clickDisabled: true,
      selectRow: null,
      // 遮罩层
      visible: false,
      // 选中数组值
      tables: [],
      // 总条数
      total: 0,
      // 表数据
      productInfoList: [],
      //选择的物资列表
      selectProductList: [],
      //物资类型
      productConfigOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        code: null,
        name: null,
        type: null,
        depotId: null,
        depotSpaceId: null,
        materialId: null,
        qrUrl: null,
      },
    };
  },
  created() {
    this.getProductConfigList();
  },
  methods: {
    // 显示弹框
    show(id) {
      this.queryParams.depotId = id;
      this.getList();
      this.visible = true;
    },
    getProductConfigList() {
      this.loading = true;
      listProduct().then((response) => {
        this.productConfigOptions = response.data;
        if (this.productConfigOptions.length > 0) {
          this.queryParams.type = this.productConfigOptions[0].id;
        }
        this.loading = false;
      });
    },
    //改变一页的数量
    handleSizeChange(val) {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = val;
      this.getList();
    },
    //改变页码
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },
    // 查询表数据
    getList() {
      this.loading = true;
      listProductInfo(this.queryParams).then((response) => {
        this.productInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectProductList = selection;
      this.buttonStatus();
    },
    selectionChange(row) {
      this.selectRow = row;
      this.buttonStatus();
    },
    buttonStatus() {
      if (this.selectProductList == null) {
        this.clickDisabled = true;
      } else {
        this.clickDisabled = false;
      }
    },
    /** 提交按钮 */
    submit() {
      this.$emit("childFn", this.selectProductList);
      this.visible = false;
    },
  },
};
</script>
